﻿#region Copyright Notice
// This file is part of GestionPedago.
// <description>
// Copyright (C) 2012 ENI Ecole Informatique
// 
// GestionPedago is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// <program> is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Collections.ObjectModel;
using GestionPedago.Services.ES.Modele;
using GestionPedago.Services;
using GestionPedago.Services.ES;

namespace GestionPedago.ViewModel
{
    /// <summary>
    /// Classe qui représente l'onglet de recherche de stagiaire
    /// </summary>
    public class RechercheStagiaireVM : OngletVM
    {

        private ICommand rechercherStagiaireCommand;
        public ICommand RechercherStagiaireCommand
        {
            get
            {
                if (this.rechercherStagiaireCommand == null)
                    this.rechercherStagiaireCommand = new RelayCommand(param => this.LancerRechercherStagiaire());

                return this.rechercherStagiaireCommand;
            }
        }

        /// <summary>
        /// Lance la recherche de stagiaire avec les critères sélectionnés
        /// </summary>
        private void LancerRechercherStagiaire()
        {

            RechercherStagiairesIn criteresRecherche = new RechercherStagiairesIn(
                                                            this.Nom,
                                                            this.Prenom,
                                                            this.Ville,
                                                            this.CodePostal,
                                                            this.Region.CodeRegion,
                                                            this.CreeDepuis,
                                                            this.Promotion,
                                                            this.Entreprise
                                                        );

            Stagiaires.Clear();

            foreach (StagiaireES s in FacadeServices.GetInstance().RechercherStagiaires(criteresRecherche).ListeStagiaires)
                Stagiaires.Add(s);
                                                    
        }


        private ICommand resetRechercheStagiaireCommand;
        public ICommand ResetRechercheStagiaireCommand {
            get {
                if(this.resetRechercheStagiaireCommand == null)
                    this.resetRechercheStagiaireCommand = new RelayCommand(param => this.ReinitRechercheStagiaire());

                return this.resetRechercheStagiaireCommand;
            }
        }

        /// <summary>
        /// Réinitialise les critères de la recherche de stagiaire
        /// </summary>
        private void ReinitRechercheStagiaire() {
      
            this.Nom = string.Empty;
            this.Prenom = string.Empty;
            this.Ville = string.Empty;
            this.CodePostal = string.Empty;
            this.CreeDepuis = new DateTime();
            Regions = FacadeServices.GetInstance().RecupererRegions().ListeRegions;
            Promotions = FacadeServices.GetInstance().RecupererPromotions(new RecupererPromotionsIn()).ListePromotions;
            Entreprises = FacadeServices.GetInstance().RecupererEntreprises(new RecupererEntreprisesIn()).ListeEntreprises;

            this.Region = Regions[0]; 
                                                       
            Stagiaires.Clear();

        }

        private string pNom;
        /// <summary>
        /// Critère de recherche Nom 
        /// </summary>
        public string Nom 
        {
            get { return pNom; }
            set 
            {
                pNom = value;
                RaisePropertyChanged("Nom");
            }
        }

        private string pPrenom;
        /// <summary>
        /// Critère de recherche Prénom
        /// </summary>
        public string Prenom 
        {
            get { return pPrenom; }
            set {
                pPrenom = value;
                RaisePropertyChanged("Prenom");
            }
        }
        
        private string pVille;
        /// <summary>
        /// Critère de recherche Ville 
        /// </summary>
        public string Ville 
        {
            get { return pVille; }
            set {
                pVille = value;
                RaisePropertyChanged("Ville");
            }
        }

        private string pCodePostal;
        /// <summary>
        /// Critère de recherche Code Postal
        /// </summary>
        public string CodePostal
        {
            get { return pCodePostal; }
            set {
                pCodePostal = value;
                RaisePropertyChanged("CodePostal");
            }
        }

        private List<RegionES> pRegions;
        /// <summary>
        /// Liste de toutes les régions
        /// </summary>
        public List<RegionES> Regions
        {
            get { return pRegions; }
            set {
                pRegions = value;
                RaisePropertyChanged("Regions");
            }
        }

        private RegionES pRegion;
        /// <summary>
        /// Critère de recherche Region 
        /// </summary>
        public RegionES Region 
        {
            get { return pRegion; }
            set {
                pRegion = value;
                RaisePropertyChanged("Region");
            }
        }

        private DateTime pCreeDepuis;
        /// <summary>
        /// Critère de recherche Date de création
        /// </summary>
        public DateTime CreeDepuis 
        {
            get { return pCreeDepuis; }
            set {
                pCreeDepuis = value;
                RaisePropertyChanged("CreeDepuis");
            }
        }

        private List<PromotionES>pPromotions;
        /// <summary>
        /// Liste de toutes les promotions
        /// </summary>
        public List<PromotionES> Promotions
        {
            get { return pPromotions; }
            set {
                pPromotions = value;
                RaisePropertyChanged("Promotions");
            }
        }

        private PromotionES pPromotion;
        /// <summary>
        /// Critère de recherche Promotion
        /// </summary>
        public PromotionES Promotion 
        {
            get { return pPromotion; }
            set {
                pPromotion = value;
                RaisePropertyChanged("Promotion");
            }
        }

        private List<EntrepriseES> pEntreprises; 
        /// <summary>
        /// Liste de toutes les entreprises
        /// </summary>
        public List<EntrepriseES> Entreprises 
        {
            get { return pEntreprises; }
            set {
                pEntreprises = value;
                RaisePropertyChanged("Entreprises");
            }
        }

        private EntrepriseES pEntreprise;
        /// <summary>
        /// Critère de recherche Entreprise 
        /// </summary>
        public EntrepriseES Entreprise 
        {
            get { return pEntreprise; }
            set {
                pEntreprise = value;
                RaisePropertyChanged("Entreprise");
            }
        }

        /// <summary>
        /// Liste des stagiaires trouvés
        /// </summary>
        public ObservableCollection<StagiaireES> Stagiaires { get; set; }


        /// <summary>
        /// Constructeur de la classe RechercheStagiaireVM
        /// </summary>
        /// <param name="parent">Gestionnaire d'onglets</param>
        public RechercheStagiaireVM(GestionnaireOngletsVM parent)
        {
            base.DisplayName = "Rechercher un stagiaire";
            base.Parent = parent;

            this.Nom = "";
            this.Prenom = "";
            this.Ville = "";
            this.CodePostal = "";

            Regions = FacadeServices.GetInstance().RecupererRegions().ListeRegions;
            Promotions = FacadeServices.GetInstance().RecupererPromotions(new RecupererPromotionsIn()).ListePromotions;
            Entreprises = FacadeServices.GetInstance().RecupererEntreprises(new RecupererEntreprisesIn()).ListeEntreprises;

            this.Region = Regions[0];

            Stagiaires = new ObservableCollection<StagiaireES>();
        }


    }
}
